package cn.ingrun.first_spring_cloud_client.utils;

import cn.ingrun.first_spring_cloud_client.models.ResponseJson;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.util.MultiValueMap;


// 自定义返回的response
public class MyResponse extends ResponseEntity<ResponseJson> {
    public MyResponse(HttpStatus status) {
        super(status);
    }

    public MyResponse(ResponseJson body, HttpStatus status) {
        super(body, status);
    }

    public MyResponse(MultiValueMap<String, String> headers, HttpStatus status) {
        super(headers, status);
    }

    public MyResponse(ResponseJson body, MultiValueMap<String, String> headers, HttpStatus status) {
        super(body, headers, status);
    }

    public static MyResponse success(){
        return new MyResponse(HttpStatus.OK);
    }

    public static MyResponse success(HttpStatus httpStatus){
        return new MyResponse(httpStatus);
    }

    public static MyResponse success(int code, String message, Object data){
        return new MyResponse(new ResponseJson(code, message, data), HttpStatus.OK);
    }

    public static MyResponse success(ResponseJson responseJson){
        return new MyResponse(responseJson, HttpStatus.OK);
    }

    public static MyResponse success(int code, String message, Object data, HttpStatus httpStatus){
        return new MyResponse(new ResponseJson(code, message, data), httpStatus);
    }

    public static MyResponse success(String message){
        return new MyResponse(new ResponseJson(1, message, ""), HttpStatus.OK);
    }

    public static MyResponse success(Object date){
        return new MyResponse(new ResponseJson(1, "success", date), HttpStatus.OK);
    }

    public static MyResponse success(String message, Object date){
        return new MyResponse(new ResponseJson(1, message, date), HttpStatus.OK);
    }

    public static MyResponse error(int code, String message, Object data, HttpStatus httpStatus){
        return new MyResponse(new ResponseJson(code, message, data), httpStatus);
    }

    public static MyResponse error_404(){
        return new MyResponse(new ResponseJson(0, "未找到相关信息", ""), HttpStatus.NOT_FOUND);
    }

    public static MyResponse error(String message){
        return new MyResponse(new ResponseJson(0, message, ""), HttpStatus.BAD_REQUEST);
    }

    public static MyResponse error(String message,HttpStatus httpStatus){
        return new MyResponse(new ResponseJson(0, message, ""), httpStatus);
    }

    public static MyResponse error(ResponseJson responseJson,HttpStatus httpStatus){
        return new MyResponse(responseJson, httpStatus);
    }
    public static MyResponse error(ResponseJson responseJson){
        return new MyResponse(responseJson, HttpStatus.BAD_REQUEST);
    }

}
